package com.guigu.liuzhireng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.liuzhireng.mapper.WorkMapper;
import com.guigu.liuzhireng.pojo.PageVo;
import com.guigu.liuzhireng.pojo.Work;
import com.guigu.liuzhireng.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkServiceImpl implements WorkService {

    @Autowired
    WorkMapper workMapper;

    @Override
    public int insert(Work work) {
        return workMapper.insert(work);
    }

    @Override
    public int update(Work work) {
        return workMapper.updateByPrimaryKeySelective(work);
    }

    @Override
    public int delete(Integer wid) {
        return workMapper.deleteByPrimaryKey(wid);
    }

    @Override
    public PageVo<Work> Page(Work work, int num, int size) {
        PageHelper.startPage(num,size);
        List<Work> list = workMapper.WorkAll(work);
        PageInfo<Work> pageInfo = new PageInfo<>(list);

        PageVo<Work> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        return pageVo;
    }
}
